
using System;
using Qdb.CS.Internal.Messages;
using Qdb.Ext;
using Qdb.Internal;

namespace Qdb.CS.Internal.Messages
{
	public class MReadReaderById : MsgD, IMessageWithResponse
	{
		public Msg ReplyFromServer()
		{
			ByteArrayBuffer bytes = null;
			// readWriterByID may fail in certain cases, for instance if
			// and object was deleted by another client
			try
			{
				lock (StreamLock())
				{
					bytes = Stream().ReadReaderByID(Transaction(), _payLoad.ReadInt(), _payLoad.ReadInt
						() == 1);
				}
				if (bytes == null)
				{
					bytes = new ByteArrayBuffer(0);
				}
			}
			catch (QdbRecoverableException exc)
			{
				throw;
			}
			catch (Exception exc)
			{
				throw new QdbRecoverableException(exc);
			}
			return Msg.ReadBytes.GetWriter(Transaction(), bytes);
		}
	}
}
